<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap{
    
    protected function _initSession() {
        Zend_Session::start();
    }
    
    protected function _initLocale() {
        $locale = new Zend_Locale('vi_VN');
        //Khi khởi tạo zend_registry set tên đối tượng là lớp của zend thì 
        //giá trị mặc định sẽ được gán khi khởi tạo lớp
        Zend_Registry::set('Zend_Locale', $locale);
    }
    /*
    protected function _initFoo() {
        echo '<br/>' . __METHOD__;
    }*/
    
    protected function _initDb() {
	mb_http_output ('UTF-8');
    $optionResouces = $this->getOption('resources');
    $dbOption       = $optionResouces['db'];
    $dbOption['params']['username'] = 'root';
    $dbOption['params']['password'] = 'root';
    $dbOption['params']['dbname'] = 'shop';

    $adapter        = $dbOption['adapter'];
    $config         = $dbOption['params'];
    $db             = Zend_Db::factory($adapter, $config);
    $db->setFetchMode(Zend_Db::FETCH_ASSOC);
    $db->query("SET NAMES 'utf8'");
    $db->query("SET CHARACTER SET 'utf8'");

    Zend_Registry::set('connectDb', $db);

    Zend_Db_Table::setDefaultAdapter($db);

    return $db;
    }
    
    protected function _initFrontcontroller() {
        $front = Zend_Controller_Front::getInstance();
        $front->addModuleDirectory(APPLICATION_PATH . '/modules');
        $front->setDefaultModule('default');
        //$front->registerPlugin(new Zendvn_Plugin_Test());
        $front->registerPlugin(new Zendvn_Plugin_Permission());
        
        /*$error = new Zend_Controller_Plugin_ErrorHandler(array('module'=>'default','controller'=>'public','action'=>'error'));
        $front->registerPlugin($error);*/
        return $front;
    }
    
    protected function _initLoadRouter() {
        
        $config = new Zend_Config_Ini(CONFIG_PATH . '/app-router.ini','setup-router');
        $objRouter = new Zend_Controller_Router_Rewrite();
        //new Zend_Controller_Router_Route_Regex()
        $router = $objRouter->addConfig($config,'routers');

        $front = Zend_Controller_Front::getInstance();
        $front->setRouter($router);
    }
}